class Queue {
  constructor() {
    this.items = {};
    this.count = 0;
    this.first = 0;
  }
  enqueue(val) {
    this.items[this.count] = val;
    this.count++;
  }
  dequeue() {
    if (this.count === 0) {
      return undefined;
    }
    let result = this.items[this.first];
    delete this.items[this.first];
    this.first++;
    return result;
  }
  size() {
    return this.count - this.first;
  }
  isEmpty() {
    return this.count - this.first === 0;
  }
  peek() {
    return this.items[this.first];
  }
  toString() {
    if (this.isEmpty()) "";
    let objString = `${this.items[this.first]}`;
    for (let i = this.first + 1; i < this.count; i++) {
      objString = `${objString} ${this.items[i]}`;
    }
    return objString;
  }
}
let queue = new Queue();
queue.enqueue(12);
queue.enqueue(11);
queue.enqueue(10);
queue.enqueue(9);
queue.dequeue();
console.log(queue.toString());
